import config from '../config'

let fns = {}

/**
 * 获取课表信息
 */
fns.get = (params, success, fail) => {
  // dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/course/page',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      // dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      // dd.hideLoading();
      fail && fail('网络异常')
    }

  });
}


/**
 * 添加课表信息
 */
fns.add = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/course/add',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });

}

/**
 * 添加课表信息
 */
fns.delete = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/course/delete',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });
},

/**
 * 申请报名
 */
fns.apply = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/signup/apply',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });

}

/**
 * 取消报名
 */
fns.cancel = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/signup/cancelApply',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    }

  });

}

/**
 * 签到
 */
fns.sign = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/signup/signup',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

/**
 * 立木核销
 */
fns.limuHX = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/limu/writeOff',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

/**
 * 签到
 */
fns.authentication = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({

    url: config.domain + '/ranking/authentication',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

/**
 * 报名列表
 */
fns.signInList = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/signup/list',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

/**
 * 班级列表
 */
fns.classesList = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/class/base/page',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

fns.createClasses = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/class/base/add',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

fns.studentListUpdate = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/class/base/updateExtData',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),

    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}

/**
 * 二维码
 */
fns.getStudentName = (params, success, fail) => {
  dd.showLoading();

  dd.httpRequest({
    url: config.domain + '/class/base/listStudentName',
    headers: {
      "Content-Type": "application/json"
    },
    method: 'POST',
    dataType: 'json',
    data: JSON.stringify(params),
    success: (res) => {
      dd.hideLoading();
      if (res.data.code == 0) {
        success && success(res)
      } else {
        fail && fail(res.data.message)
      }
    },

    fail: () => {
      dd.hideLoading();
      fail && fail('网络异常')
    },
  });
}


module.exports = fns